﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using YiSha.Enums;

namespace YiSha.Util.Model
{
    public class BaseRequest
    {

        /// <summary>
        /// 登录用户
        /// </summary>
        public int ActiveUser { get; set; }

        /// <summary>
        /// 请求Header
        /// </summary>
        public ReqHeader Header { get; set; }
    }
    public class ReqHeader
    {
        /// <summary>
        /// 设备id
        /// </summary>
        public string DeviceId { get; set; }
        /// <summary>
        /// 设备名称
        /// </summary>
        public string DeviceName { get; set; }
        /// <summary>
        /// 操作系统及cpu名称
        /// </summary>
        public string OsName { get; set; }
        /// <summary>
        /// 浏览器的信息
        /// </summary>
        public string OsVersion { get; set; }
        /// <summary>
        /// 版本名称
        /// </summary>
        public string VersionName { get; set; }
        /// <summary>
        /// 版本号
        /// </summary>
        public string VersionCode { get; set; }
        /// <summary>
        /// 凭证
        /// </summary>
        public string Token { get; set; }
        /// <summary>
        /// 接口名称
        /// </summary>
        public string Cmd { get; set; }
        /// <summary>
        /// 请求来源 （1-web）
        /// </summary>
        public int Source { get; set; }

        /// <summary>
        /// 签名（接口名称+账号标识+时间戳,以“|”分割）
        /// </summary>
        public string Sign { get; set; }

        /// <summary>
        /// 请求时间戳
        /// </summary>
        public int Timestamp { get; set; }
    }
    /// <summary>
    /// 请求返回信息
    /// </summary>
    [Serializable]
    [DataContract]
    public class RespResult
    {
        /// <summary>
        /// 状态码(默认返回成功 1000)
        /// </summary>
        [DataMember]
        [JsonProperty(PropertyName = "code")]
        public int Code { get; set; } = MsgCode.Success.ParseToInt();
        /// <summary>
        /// 状态信息
        /// </summary>
        [DataMember]
        [JsonProperty(PropertyName = "msg")]
        public string Msg
        {
            get
            {
                if (string.IsNullOrEmpty(_statusMsg))
                {
                    return "操作成功";
                }
                return _statusMsg;
            }
            set
            {
                _statusMsg = value;
            }
        }
        [DataMember]
        [JsonProperty(PropertyName = "cmd")]
        public string cmd { get; set; }
        /// <summary>
        /// 描述信息
        /// </summary>
        [DataMember]
        [JsonProperty(PropertyName = "dscription")]
        public string Description { get; set; }
        
        private string _statusMsg;

        private MsgCode _msgCode;
        public MsgCode MsgCode
        {
            set { Code = (int)value; _msgCode = value; }
            get { return _msgCode; }
        }
    }
    /// <summary>
    /// 分页请求参数
    /// </summary>
    public class PageListReq : BaseRequest
    {
        /// <summary>
        /// 页码
        /// </summary>
        public int pageIndex { get; set; }
        /// <summary>
        /// 每页所包含的数据条数
        /// </summary>
        public int pageSize { get; set; }
        /// <summary>
        /// 是否返回总条数
        /// </summary>
        public bool returnTotalCount { get; set; }
    }
}
